import anim from '@dfeidao/atom-web/animation/anim';
import play from '@dfeidao/atom-web/animation/play';
import { IFeidaoAiBrowserComponent } from '@dfeidao/atom-web/interfaces';
import remove from '@dfeidao/atom-web/local/remove';
import set from '@dfeidao/atom-web/local/set';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import render from '@dfeidao/atom-web/render/render';
import s_get from '@dfeidao/atom-web/storage/get';
import set_node_cls from '@dfeidao/atom-web/ui/set-node-cls';
import set_nodes_cls from '@dfeidao/atom-web/ui/set-nodes-cls';

// import { send_msg as url, get_user_info } from './config';
import p001 from './p001';

export default async function a001(fd: IFeidaoAiBrowserComponent, args: { _id: string, systemid: string, arr: object[], role_type_name: string }) {
	set(fd, 'role_type_name', args.role_type_name);
	const data = args;
	play(anim(fd.data.node, {
		repeat: 0,
		duration: 800,
		units: 'px',
		delay: 0,
		easing: 'ease', // 动画效果 默认为'ease'
		precent: 0// 动画暂停时长 单位是ms
	}, {
			right: {
				start: -676,
				end: 0
			}
		}));

	set(fd, '_id', data._id); // 角色类型id
	// const user = await whoami(get_user_info);
	// console.log(user)
	const prid = await s_get('productid');
	set(fd, 'productid', prid);

	const query = {
		filter: { productid: prid }
	};
	// const res = await nodejs<{ dataArray: object[] }>(url, './permissions/role_type_find1', query, false, false);
	const res = await nodejs<{ dataArray: object[] }>('role-type/zj-000004/s001', query);
	data.arr = res.dataArray;

	// console.log(data);
	const nodes = Array.from(fd.data.node.querySelectorAll('[tab1]')) as HTMLElement[];
	const a = Array.from(fd.data.node.querySelectorAll('[tab]')) as HTMLElement[];
	const node = fd.data.node.querySelector<HTMLDivElement>('[data-feidao-id="tab1"]');
	const b = fd.data.node.querySelector('[tab2]') as HTMLElement;
	set_nodes_cls(nodes, 'bg-themef', false);
	// set_nodes_cls(nodes, 'color-f', false);
	set_nodes_cls(nodes, 'bg-f4', true);
	set_node_cls(b, 'bg-themef', true);
	// set_node_cls(b, 'color-f', true);
	set_node_cls(b, 'bg-f4', false);
	set_nodes_cls(a, 'display-n', true);
	set_node_cls(node, 'display-n', false);

	render(fd, data, p001, 'p001', 'inner');

	fd.data.node.querySelector<HTMLSelectElement>('#sysid').value = data.systemid;
	// arr role_sysarr
	remove(fd, 'objarr');
	remove(fd, 'sysobjarr');
	remove(fd, 'arr');
	remove(fd, 'role_sysarr');
	remove(fd, 'res.dataArray');



}
